const router = require('koa-router')();
const {login,register,logout} = require('./../controller/UserController')
const {getIp} = require('./../utils/util')
const log4js = require('./../utils/log4j')
router.prefix('/users');

router.post('/login', async function (ctx, next) {
  const {userName, userPwd} = ctx.request.body
  const res = await login({userName, userPwd,lastLoginIp:getIp(ctx.req)})
  ctx.body = res
});

router.post('/register', async function (ctx, next) {
  const {userName, userPwd} = ctx.request.body;
  const res = await register({userName, userPwd,lastLoginIp:getIp(ctx.req)})
  ctx.body = res
});

router.post('/logout', async function (ctx, next) {
  const token = ctx.request.headers.authorization
  const res = await logout(token)
  ctx.body = res;
});



module.exports = router;
